package com.ukao.pad.ui.splash;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ukao.pad.R;
import com.ukao.pad.base.BaseFragment;
import com.ukao.pad.bean.ActrivateBean;
import com.ukao.pad.retrofit.ApiCallback;
import com.ukao.pad.utils.T;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;


public class BindingCardFragment extends BaseFragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.back_btn)
    TextView backBtn;
    @BindView(R.id.splash_title)
    TextView splashTitle;
    @BindView(R.id.verify_btn)
    TextView verifyBtn;
    Unbinder unbinder;


    private String strSerialNum;
    private String mParam2;
    public boolean isActivateCode;

    public static BindingCardFragment newInstance(String param1, String param2) {
        BindingCardFragment fragment = new BindingCardFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            strSerialNum = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    protected void initView() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_binding_card, container, false);
        unbinder = ButterKnife.bind(this, view);

        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.back_btn, R.id.verify_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_btn:
                finish();
                break;
            case R.id.verify_btn:
                isActivate();
                break;
        }
    }

    /**
     *是否激活序列号   90665439/97018276
     */
    public void isActivate (   ) {
        showProgressDialog();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("serialNum",strSerialNum);
        addSubscription(apiStores().isActivate(mHashMap),
                new ApiCallback<ActrivateBean>() {

                    @Override
                    public void onSuccess(ActrivateBean model) {
                        if (model.getHttpCode()==200){
                            int  state=model.getData().getState();
                            if (state!=0){/*不为0时可激活*/
                                start(StartUseFragment.newInstance("",""));
                            }else{
                                T.show(model.getData().getMsg());
                            }
                        }





                    }

                    @Override
                    public void onNoNewWork() {

                    }


                    @Override
                    public void onFinish() {
                        dismissProgressDialog();

                    }

                });
    }
}
